//
//  SISSWarmTipViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/10.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSWarmTipViewController.h"
#import <WebKit/WebKit.h>
#import "SISSBaseView.h"


@interface SISSWarmTipViewController ()

/* containerView */
@property (weak, nonatomic) SISSBaseView *containerView;

@property (weak, nonatomic) UILabel *tipLabel;

/* contentLabel */
@property (weak, nonatomic) UILabel *contentLabel;

/// startButton
@property (weak, nonatomic) UIButton *startButton;

@end

@implementation SISSWarmTipViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"温馨提示";
}

- (void)setTipStr:(NSString *)tipStr {
    _tipStr = tipStr;
    self.tipLabel.text = tipStr;
}

- (void)setTextStr:(NSString *)textStr {
    _textStr = textStr;
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //    paraStyle.alignment = NSTextAlignmentLeft;  //对齐
    //    paraStyle.headIndent = 0.0f;//行首缩进
    //参数：（字体大小17号字乘以2，34f即首行空出两个字符）
    //    CGFloat emptylen = self.contractOneLabel.font.pointSize * 2;
    //    paraStyle.firstLineHeadIndent = emptylen;//首行缩进
    //    paraStyle.tailIndent = 0.0f;//行尾缩进
    paraStyle.lineSpacing = 16.0f;//行间距
    
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:textStr attributes:@{NSParagraphStyleAttributeName:paraStyle}];
    self.contentLabel.attributedText = attrText;
    
}

- (void)setBottomButtonStr:(NSString *)bottomButtonStr {
    _bottomButtonStr = bottomButtonStr;
    if (bottomButtonStr.length == 0) {
        self.startButton.hidden = YES;
    }
    if ([bottomButtonStr isEqualToString:@"已交房"]) {
        self.startButton.userInteractionEnabled = NO;
    }
    [self.startButton setTitle:bottomButtonStr forState:UIControlStateNormal];
}

- (void)setupSubviews {
    [super setupSubviews];
    
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView];
    
    // 1. 添加一个视图，四周和 scrollView 一致
    SISSBaseView *containerView = [[SISSBaseView alloc] init];
    containerView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:containerView];
    self.containerView = containerView;
    
    // 2. 自动布局
    WeakSelf
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        if (@available(iOS 11.0, *)) {
            make.top.equalTo(weakSelf.mas_topLayoutGuideBottom);
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(-44);
        } else {
            make.top.equalTo(weakSelf.view);
            make.bottom.equalTo(weakSelf.view).offset(-44);
        }
    }];
    [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.mas_equalTo([SISSPublicSingleton shared].screenWidth);
        // 通过宽高设置 contentSize
        //        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT * 1.5));
    }];
    
    UILabel *tipLabel = [[UILabel alloc] init];
    tipLabel.textColor = COLOR(0x334A60);
    tipLabel.font = [UIFont boldSystemFontOfSize:18];
    tipLabel.text = @"温馨提示：";
    [self.containerView addSubview:tipLabel];
    self.tipLabel = tipLabel;
    
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.textColor = COLOR(0x334A60);
    contentLabel.font = [UIFont systemFontOfSize:15];
    contentLabel.numberOfLines = 0;
    NSString *text = @"1.根据我国《合同法》、《电子签名法》以及其他相关法律法规，电子合同与纸质合同具有同等法律效应。\n2.合同是当事人基于信任，在协商的基础上意思表示一致的民事法律行为。合同履行过程中所承担的风险将由合同当事人自行承担，因此在签署前请务必确认对方的身份、联系方式的真实性及合同内容的准确性，谨慎处理。";
//    [UILabel changeLineSpaceForLabel:contentLabel WithSpace:4];
    [self.containerView addSubview:contentLabel];
    self.contentLabel = contentLabel;
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //    paraStyle.alignment = NSTextAlignmentLeft;  //对齐
    //    paraStyle.headIndent = 0.0f;//行首缩进
    //参数：（字体大小17号字乘以2，34f即首行空出两个字符）
//        CGFloat emptylen = self.contentLabel.font.pointSize * 2;
//        paraStyle.firstLineHeadIndent = emptylen;//首行缩进
//        paraStyle.tailIndent = 0.0f;//行尾缩进
    paraStyle.lineSpacing = 15.0f;//行间距
    
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:text attributes:@{NSParagraphStyleAttributeName:paraStyle}];
    contentLabel.attributedText = attrText;

    
    //    WKWebView *webView = [[WKWebView alloc] init];
    //    [self.view addSubview:webView];
    //
    //    NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:self.urlStr withExtension:@"html"];
    //    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileUrl];
    //    [webView loadRequest:request];
    
    UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [startButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [startButton setBackgroundColor:MAIN_COLOR];
    [startButton setTitle:@"已阅知" forState:UIControlStateNormal];
    [startButton addTarget:self action:@selector(startButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:startButton];
    self.startButton = startButton;
    
    // 自动布局
    CGFloat margin = 8.0;
//    WeakSelf
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.containerView).offset(2 * margin);
        make.left.equalTo(weakSelf.containerView).offset(margin);
    }];
    
    //    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(tipLabel.mas_bottom);
    //        make.left.right.equalTo(self.view);
    //        make.bottom.equalTo(startButton.mas_top);
    //    }];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tipLabel.mas_bottom).offset(margin);
        make.left.equalTo(weakSelf.containerView).offset(margin);
        make.right.bottom.equalTo(weakSelf.containerView).offset(-margin);
    }];
    
    [startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(44);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(weakSelf.view);
        }
    }];
}

#pragma mark - 开始按钮点击事件
- (void)startButtonClickAction {
    
   
}

@end
